<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Python日记 -- 百度OCR翻译 | Reverse</title><meta name="keywords" content="分享,python"><meta name="author" content="Reverse"><meta name="copyright" content="Reverse"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前言最近写了个 丐版 的 百度 OCR 翻译 ，其实网络上也有很多类似的源码。   该教程为 简化版 ，详细查看 技术文档 ， 支持 python 版本 2.7.+ 和 3.+ 。     效果展示  百度OCR准备工作 登录 &#x2F; 注册 百度账号  创建 通用场景OCR ，应用归属 选择 个人 ，应用名称 和 应用描述 自定义  填完以上信息后，点击 立即创建 (注意要实名认证)  此时，应用列表"><meta property="og:type" content="article"><meta property="og:title" content="Python日记 -- 百度OCR翻译"><meta property="og:url" content="https://blog.c12th.cn/archives/7.html"><meta property="og:site_name" content="Reverse"><meta property="og:description" content="前言最近写了个 丐版 的 百度 OCR 翻译 ，其实网络上也有很多类似的源码。   该教程为 简化版 ，详细查看 技术文档 ， 支持 python 版本 2.7.+ 和 3.+ 。     效果展示  百度OCR准备工作 登录 &#x2F; 注册 百度账号  创建 通用场景OCR ，应用归属 选择 个人 ，应用名称 和 应用描述 自定义  填完以上信息后，点击 立即创建 (注意要实名认证)  此时，应用列表"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://pic.imgdb.cn/item/6298e4f10947543129bb7f3b.png"><meta property="article:published_time" content="2022-06-02T12:27:00.000Z"><meta property="article:modified_time" content="2022-06-07T03:34:45.340Z"><meta property="article:author" content="Reverse"><meta property="article:tag" content="分享"><meta property="article:tag" content="python"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://pic.imgdb.cn/item/6298e4f10947543129bb7f3b.png"><link rel="shortcut icon" href="https://pic.imgdb.cn/item/624aa2ca239250f7c5145d0d.png"><link rel="canonical" href="https://blog.c12th.cn/archives/7"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><meta name="baidu-site-verification" content="code-rC4nCAcQWi"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free@6.1.1/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/css/snackbar.min.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"search.xml",languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:{defaultEncoding:2,translateDelay:0,msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"簡"},noticeOutdate:{limitDay:500,position:"top",messagePrev:"一年后",messageNext:"这篇文章可能存在过期，看看是否需要更新"},highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:200},copy:{success:"复制成功",error:"复制错误",noSupport:"浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"天",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:void 0,lightbox:"fancybox",Snackbar:{chs_to_cht:"你已切换为繁体",cht_to_chs:"你已切换为简体",day_to_night:"你已切换为深色模式",night_to_day:"你已切换为浅色模式",bgLight:"#49b1f5",bgDark:"#121212",position:"top-center"},source:{jQuery:"https://npm.elemecdn.com/ajax/libs/jquery/3.6.0/jquery.min.js",justifiedGallery:{js:"https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/jquery.justifiedGallery.min.js",css:"https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/css/justifiedGallery.min.css"},fancybox:{js:"https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/jquery.fancybox.min.js",css:"https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/css/jquery.fancybox.min.css"}},isPhotoFigcaption:!0,islazyload:!0,isanchor:!1}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2022-06-07 11:34:45"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)});const t=saveToLocal.get("aside-status");void 0!==t&&("hide"===t?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"))})(window)</script><script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script><script>LA.init({id:"JiVSQJjI3x7VPhPR",ck:"JiVSQJjI3x7VPhPR"})</script><script src="https://sdk.51.la/perf/js-sdk-perf.min.js" crossorigin="anonymous"></script><script>(new LingQue.Monitor).init({id:"JiVU7VsCXFtXCgz7"})</script><meta name="360-site-verification" content="df2d32f8a9b9edd0ca0a3ce43b55a425"><meta name="google-site-verification" content="zAK7hI2do_tbjWAKeVf7F18ODGi3lW95XCKnMlCGCJ0"><meta name="msvalidate.01" content="5B0D3E6DB3A756AC912955346D3F58AA"><style>blockquote,body,code,dd,div,dl,dt,fieldset,form,h1,h2,h3,h4,h5,h6,input,legend,li,ol,p,pre,td,textarea,th,ul{margin:0;padding:0}video#bgvid{position:fixed;right:0;bottom:0;min-width:100%;min-height:100%;width:auto;height:auto;z-index:-100}video{display:block}</style><link rel="stylesheet" href="/css/custom.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="//at.alicdn.com/t/font_3371316_eyujecx4lfh.css"><link rel="stylesheet" href="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/diy/plugins.min.css"><link rel="stylesheet" href="https://gcore.jsdelivr.net/gh/zhheo/JS-Heo@main/rightmenu/rightmenu.css"><link rel="stylesheet" href="/css/heoMainColor.css"><link rel="stylesheet" href="https://npm.elemecdn.com/reverse-stu-allversions@1.0.17/butterfly/swiper/swiper.min.css"><link rel="stylesheet" href="https://npm.elemecdn.com/reverse-stu-allversions@1.0.17/butterfly/swiper/swiperstyle.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.css"><link rel="stylesheet" href="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload='this.media="screen"'><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload='this.media="all"'><script src="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="Reverse" type="application/atom+xml"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.0/img/202203071633899.gif" onerror='onerror=null,src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/img/505.gif"' alt="avatar"></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div></div></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-home"></i> <span>主页</span><i class="fas iconfont icon-xiabiao expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="https://blog.c12th.cn"><i class="fa-fw fas iconfont icon-zhuye"></i> <span>主站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://lowblog.vercel.app"><i class="fa-fw fas iconfont icon-bianjizhandian"></i> <span>演示版</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://c12th.cn"><i class="fa-fw fas iconfont icon-yu1"></i> <span>分站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://next.c12th.cn"><i class="fa-fw fas iconfont icon-16gl-N"></i> <span>Next</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://jsimple.c12th.cn"><i class="fa-fw fas iconfont icon-leaf"></i> <span>Hugo</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://sakuraplus.c12th.cn"><i class="fa-fw fas iconfont icon-yinghua"></i> <span>樱花</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i> <span>归档</span></a></div><div class="menus_item"><a class="site-page" href="/fcircle/"><i class="fa-fw fa fa-puzzle-piece"></i> <span>朋友圈</span></a></div><div class="menus_item"><a class="site-page" href="/artitalk/"><i class="fa-fw fas iconfont icon-xiayu"></i> <span>碎碎念</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-comment-dots"></i> <span>留言板</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-paper-plane"></i> <span>功能箱</span><i class="fas iconfont icon-xiabiao expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://waline.c12th.cn/ui"><i class="fa-fw fas iconfont icon-pinglun1"></i> <span>评论后台</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://dashboard.daovoice.io/"><i class="fa-fw fas iconfont icon-pinglun2"></i> <span>在线后台</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://check.c12th.cn"><i class="fa-fw fas iconfont icon-icon-tpian"></i> <span>网站监控</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://kz.c12th.cn"><i class="fa-fw fas iconfont icon-kouzhao1"></i> <span>带上口罩</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="http://12thstan.ga/view"><i class="fa-fw fas iconfont icon-zhongqi fa-spin"></i> <span>人生重开</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="http://www.mipcode.com/m/Reverse/FkFYwT91fwzjN3wrGZUFWzX"><i class="fa-fw fas iconfont icon-tubiaozhizuomoban-"></i> <span>小恐龙</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i> <span>友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heartbeat"></i> <span>关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url(https://pic.imgdb.cn/item/6298e4f10947543129bb7f3b.png)"><nav id="nav"><span id="blog_name"><a id="site-name" onclick="btf.scrollToDest(0,500)" data-title="欢迎来到我的博客 ~">Python日记 -- 百度OCR翻译</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas iconfont icon-sousuo3 fa-fw"></i> <span>搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-home"></i> <span>主页</span><i class="fas iconfont icon-xiabiao expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="https://blog.c12th.cn"><i class="fa-fw fas iconfont icon-zhuye"></i> <span>主站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://lowblog.vercel.app"><i class="fa-fw fas iconfont icon-bianjizhandian"></i> <span>演示版</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://c12th.cn"><i class="fa-fw fas iconfont icon-yu1"></i> <span>分站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://next.c12th.cn"><i class="fa-fw fas iconfont icon-16gl-N"></i> <span>Next</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://jsimple.c12th.cn"><i class="fa-fw fas iconfont icon-leaf"></i> <span>Hugo</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://sakuraplus.c12th.cn"><i class="fa-fw fas iconfont icon-yinghua"></i> <span>樱花</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i> <span>归档</span></a></div><div class="menus_item"><a class="site-page" href="/fcircle/"><i class="fa-fw fa fa-puzzle-piece"></i> <span>朋友圈</span></a></div><div class="menus_item"><a class="site-page" href="/artitalk/"><i class="fa-fw fas iconfont icon-xiayu"></i> <span>碎碎念</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-comment-dots"></i> <span>留言板</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-paper-plane"></i> <span>功能箱</span><i class="fas iconfont icon-xiabiao expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://waline.c12th.cn/ui"><i class="fa-fw fas iconfont icon-pinglun1"></i> <span>评论后台</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://dashboard.daovoice.io/"><i class="fa-fw fas iconfont icon-pinglun2"></i> <span>在线后台</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://check.c12th.cn"><i class="fa-fw fas iconfont icon-icon-tpian"></i> <span>网站监控</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="https://kz.c12th.cn"><i class="fa-fw fas iconfont icon-kouzhao1"></i> <span>带上口罩</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="http://12thstan.ga/view"><i class="fa-fw fas iconfont icon-zhongqi fa-spin"></i> <span>人生重开</span></a></li><li><a class="site-page child" target="_blank" rel="noopener external nofollow noreferrer" href="http://www.mipcode.com/m/Reverse/FkFYwT91fwzjN3wrGZUFWzX"><i class="fa-fw fas iconfont icon-tubiaozhizuomoban-"></i> <span>小恐龙</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i> <span>友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heartbeat"></i> <span>关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas iconfont icon-fenlei1 fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Python日记 -- 百度OCR翻译</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far iconfont icon-rili fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-06-02T12:27:00.000Z" title="发表于 2022-06-02 20:27:00">2022-06-02</time><span class="post-meta-separator">|</span><i class="fas iconfont icon-icon--gengxin fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-06-07T03:34:45.340Z" title="更新于 2022-06-07 11:34:45">2022-06-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas iconfont icon-biaoqian2 fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AD%A6%E4%B9%A0%E6%97%A5%E8%AE%B0/">学习日记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far iconfont icon-zishu fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.6k</span><span class="post-meta-separator">|</span><i class="far iconfont icon-shijian fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" data-flag-title="Python日记 -- 百度OCR翻译"><i class="far iconfont icon-yanjing fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><font size="3"><div class="note default flat"><p>最近写了个 <strong><font size="3" color="green">丐版</font></strong> 的 <strong>百度 OCR 翻译</strong> ，其实网络上也有很多类似的源码。</p></div></font><font size="3"><div class="note info flat"><p>该教程为 <strong><font size="3" color="green">简化版</font></strong> ，详细查看 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://ai.baidu.com/ai-doc/OCR/9kibizye4">技术文档</a> ， <strong><font size="3" color="red">支持 python 版本 2.7.+ 和 3.+</font></strong> 。</p></div></font><hr><p><img src="/img/loading.gif" data-lazy-src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.14/img/2022.6.2-1.gif"></p><p><strong><p align="center">效果展示</p></strong></p><hr><h1 id="百度OCR"><a href="#百度OCR" class="headerlink" title="百度OCR"></a>百度OCR</h1><h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><ol><li><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://login.bce.baidu.com/">登录</a> / <a target="_blank" rel="noopener external nofollow noreferrer" href="https://passport.baidu.com/v2/?reg">注册</a> 百度账号</p></li><li><p>创建 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://console.bce.baidu.com/ai/?_=1654272722032&amp;fromai=1#/ai/ocr/app/create">通用场景OCR</a> ，<font size="3" color="blue">应用归属</font> 选择 <code>个人</code> ，<font size="3" color="blue">应用名称</font> 和 <font size="3" color="blue">应用描述</font> <strong>自定义</strong></p></li><li><p>填完以上信息后，点击 <code>立即创建</code> <strong><font size="3" color="red">(注意要实名认证)</font></strong></p></li><li><p>此时，<font size="3" color="blue">应用列表</font> 会出现 <strong>刚创建好的应用</strong> ，分别把 <code>AppID</code> 、 <code>API Key</code> 和 <code>Secret Key</code> <strong>记录好</strong> 等下用</p></li></ol><hr><h2 id="核心代码"><a href="#核心代码" class="headerlink" title="核心代码"></a>核心代码</h2><ol><li><p>当前版本为 <font size="3" color="blue">python 3.8.1</font> <strong><font size="3" color="red">(PIL 在 python3 时，第三方库应安装 pillow)</font></strong></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 截图</span></span><br><span class="line"><span class="keyword">import</span> keyboard</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> ImageGrab</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">keyboard.wait(hotkey=<span class="string">&#x27;ctrl+c&#x27;</span>)      <span class="comment"># 触发按键</span></span><br><span class="line"></span><br><span class="line">time.sleep(<span class="number">0.01</span>)                    <span class="comment"># 延迟</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 保存图片</span></span><br><span class="line">image = ImageGrab.grabclipboard()</span><br><span class="line">image.save(<span class="string">&#x27;OCR.png&#x27;</span>)               <span class="comment"># 图片命名为&#x27;OCR.png&#x27;</span></span><br></pre></td></tr></table></figure></li><li><p>安装 <strong>OCR Python SDK</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install baidu-aip</span><br></pre></td></tr></table></figure></li><li><p>配置 <strong>OCR</strong></p></li></ol><ul><li><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://ai.baidu.com/ai-doc/OCR/wkibizyjk#%E6%96%B0%E5%BB%BAaipocr">配置AipOcr</a> ，把在 <strong>准备工作</strong> 获取的 <code>AppID</code> 、 <code>API Key</code> 和 <code>Secret Key</code> <font size="3" color="blue">对应填入</font></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 配置AipOcr</span></span><br><span class="line"><span class="keyword">from</span> aip <span class="keyword">import</span> AipOcr</span><br><span class="line"></span><br><span class="line">APP_ID = <span class="string">&#x27;你的 App ID&#x27;</span></span><br><span class="line">API_KEY = <span class="string">&#x27;你的 Api Key&#x27;</span></span><br><span class="line">SECRET_KEY = <span class="string">&#x27;你的 Secret Key&#x27;</span></span><br><span class="line"></span><br><span class="line">client = AipOcr(APP_ID, API_KEY, SECRET_KEY)</span><br></pre></td></tr></table></figure></li><li><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://ai.baidu.com/ai-doc/OCR/7kibizyfm">接口说明</a></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_file_content</span>(<span class="params">filePath</span>):</span></span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;OCR.png&#x27;</span>, <span class="string">&quot;rb&quot;</span>) <span class="keyword">as</span> fp:</span><br><span class="line">       <span class="keyword">return</span> fp.read()</span><br><span class="line"></span><br><span class="line"> image = get_file_content(<span class="string">&#x27;OCR.png&#x27;</span>)</span><br><span class="line">	</span><br><span class="line"> <span class="comment"># 调用通用文字识别（标准版）</span></span><br><span class="line"> res_image = client.basicGeneral(image)</span><br><span class="line"> <span class="built_in">print</span>(res_image)</span><br></pre></td></tr></table></figure></li><li><p><strong>删减 + 筛选数据</strong></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;OCR.png&#x27;</span>, <span class="string">&quot;rb&quot;</span>) <span class="keyword">as</span> fp:</span><br><span class="line">  image = fp.read()</span><br><span class="line"></span><br><span class="line">  <span class="comment"># 调用通用文字识别（标准版）</span></span><br><span class="line">  res_image = client.basicGeneral(image)</span><br><span class="line">  <span class="comment"># print(res_image)</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 筛选数据</span></span><br><span class="line">  res = res_image[<span class="string">&#x27;words_result&#x27;</span>]</span><br><span class="line">  <span class="keyword">for</span> i <span class="keyword">in</span> res:</span><br><span class="line">      <span class="built_in">print</span>(i[<span class="string">&#x27;words&#x27;</span>])</span><br></pre></td></tr></table></figure></li></ul><hr><h1 id="有道翻译"><a href="#有道翻译" class="headerlink" title="有道翻译"></a>有道翻译</h1><ul><li>用到了 <strong>爬虫</strong> ，<strong><font size="3" color="red">网上有教程，不细说</font></strong><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">import</span> hashlib</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 网址</span></span><br><span class="line">url = <span class="string">&#x27;https://fanyi.youdao.com/translate_o?smartresult=dict&amp;smartresult=rule&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 反爬</span></span><br><span class="line">header = &#123;</span><br><span class="line">    <span class="string">&#x27;User-Agent&#x27;</span>: <span class="string">&#x27;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;Cookie&#x27;</span>: <span class="string">&#x27;OUTFOX_SEARCH_USER_ID=1870252624@10.110.96.157; OUTFOX_SEARCH_USER_ID_NCOO=1338974472.751384; ___rl__test__cookies=1654489795853&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;Referer&#x27;</span>: <span class="string">&#x27;https://fanyi.youdao.com/&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 时间戳</span></span><br><span class="line">r = <span class="built_in">str</span>(<span class="built_in">int</span>(time.time()*<span class="number">1000</span>))</span><br><span class="line"><span class="comment"># print(r)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 随机数</span></span><br><span class="line">random_num = random.randint(<span class="number">0</span>,<span class="number">9</span>)</span><br><span class="line">i = r + <span class="built_in">str</span>(random_num)</span><br><span class="line"><span class="comment"># print(i)</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">data_new</span>(<span class="params">e</span>):</span></span><br><span class="line">    <span class="comment"># md5</span></span><br><span class="line">    str_sign = <span class="string">&quot;fanyideskweb&quot;</span> + e + i + <span class="string">&quot;Ygy_4c=r#e#4EX^NUGUc5&quot;</span></span><br><span class="line">    md5 = hashlib.md5()</span><br><span class="line">    md5.update(str_sign.encode())</span><br><span class="line">    sign = md5.hexdigest()</span><br><span class="line">    <span class="comment"># print(sign)</span></span><br><span class="line"></span><br><span class="line">    data_old = &#123;</span><br><span class="line">        <span class="string">&#x27;i&#x27;</span>: e,</span><br><span class="line">        <span class="string">&#x27;from&#x27;</span>: <span class="string">&#x27;AUTO&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;to&#x27;</span>: <span class="string">&#x27;AUTO&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;smartresult&#x27;</span>: <span class="string">&#x27;dict&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;client&#x27;</span>: <span class="string">&#x27;fanyideskweb&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;salt&#x27;</span>: i,</span><br><span class="line">        <span class="string">&#x27;sign&#x27;</span>: sign,</span><br><span class="line">        <span class="string">&#x27;lts&#x27;</span>: r,</span><br><span class="line">        <span class="string">&#x27;bv&#x27;</span>: <span class="string">&#x27;dbf26599b4389c828cae8b896c9b0708&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;doctype&#x27;</span>: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;version&#x27;</span>: <span class="string">&#x27;2.1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;keyfrom&#x27;</span>: <span class="string">&#x27;fanyi.web&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;action&#x27;</span>: <span class="string">&#x27;FY_BY_REALTlME&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> data_old</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">a = <span class="built_in">input</span>(<span class="string">&#x27;请输入需要翻译的内容：\n&#x27;</span>)</span><br><span class="line">data = data_new(a)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 请求</span></span><br><span class="line">result = requests.post(url,headers=header,data=data).text</span><br><span class="line"><span class="comment"># print(result)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据筛选</span></span><br><span class="line">dict_res = json.loads(result)</span><br><span class="line"><span class="built_in">print</span>(dict_res[<span class="string">&#x27;translateResult&#x27;</span>][<span class="number">0</span>][<span class="number">0</span>][<span class="string">&#x27;tgt&#x27;</span>])</span><br></pre></td></tr></table></figure></li></ul><hr><h1 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h1><h2 id="拓展"><a href="#拓展" class="headerlink" title="拓展"></a>拓展</h2><ul><li>增加 <strong>复制</strong> 和 <strong>弹窗</strong> 功能 <del>加了些花里胡哨的东西</del><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pyperclip</span><br><span class="line"><span class="keyword">import</span> tkinter <span class="keyword">as</span> tk</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># copy</span></span><br><span class="line">pyperclip.copy(a + <span class="string">&#x27;\n&#x27;</span> + b)</span><br><span class="line">time.sleep(<span class="number">0.02</span>)</span><br><span class="line"><span class="comment"># 弹窗</span></span><br><span class="line">root = tk.Tk()</span><br><span class="line">root.title(<span class="string">&quot;info&quot;</span>)</span><br><span class="line">tk.Label(root, text=<span class="string">&quot;已复制&quot;</span>, ).pack()       <span class="comment"># 弹窗显示</span></span><br><span class="line">root.after(<span class="number">1000</span>, <span class="keyword">lambda</span>: root.destroy())    <span class="comment"># 停留1s</span></span><br><span class="line">root.mainloop()</span><br></pre></td></tr></table></figure></li></ul><hr><h2 id="打包前-完整代码"><a href="#打包前-完整代码" class="headerlink" title="打包前 完整代码"></a>打包前 完整代码</h2><ol><li><p>演示版本为 <font size="3" color="blue">python 3.8.1</font> ， <font size="3" color="red">如出现报错请自行解决</font></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 工程：test</span></span><br><span class="line"><span class="comment"># 创建时间：2022/6/2 11:41</span></span><br><span class="line"><span class="comment"># encoding:utf-8</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> keyboard</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">import</span> hashlib</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="keyword">import</span> configparser</span><br><span class="line"><span class="keyword">import</span> pyperclip</span><br><span class="line"><span class="keyword">import</span> tkinter <span class="keyword">as</span> tk</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> ImageGrab</span><br><span class="line"><span class="keyword">from</span> aip <span class="keyword">import</span> AipOcr</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 读取ini文件</span></span><br><span class="line">aip = <span class="string">&#x27;OCR.ini&#x27;</span></span><br><span class="line">conf = configparser.ConfigParser()</span><br><span class="line">conf.read(aip)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置AipOcr</span></span><br><span class="line">APP_ID = conf.get(<span class="string">&#x27;aip&#x27;</span>, <span class="string">&#x27;APP_ID&#x27;</span>)              <span class="comment"># 你的 App ID</span></span><br><span class="line">API_KEY = conf.get(<span class="string">&#x27;aip&#x27;</span>, <span class="string">&#x27;API_KEY&#x27;</span>)            <span class="comment"># 你的 Api Key</span></span><br><span class="line">SECRET_KEY = conf.get(<span class="string">&#x27;aip&#x27;</span>, <span class="string">&#x27;SECRET_KEY&#x27;</span>)      <span class="comment"># 你的 Secret Key</span></span><br><span class="line"></span><br><span class="line">client = AipOcr(APP_ID, API_KEY, SECRET_KEY)</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">    <span class="comment">#   --------------- 截图识别 --------------</span></span><br><span class="line">    <span class="comment"># 截图</span></span><br><span class="line">    keyboard.wait(hotkey=<span class="string">&#x27;ctrl+c&#x27;</span>)      <span class="comment"># 触发按键</span></span><br><span class="line"></span><br><span class="line">    time.sleep(<span class="number">0.01</span>)                    <span class="comment"># 延迟</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 保存图片</span></span><br><span class="line">    image = ImageGrab.grabclipboard()</span><br><span class="line">    image.save(<span class="string">&#x27;OCR.png&#x27;</span>)               <span class="comment"># 图片命名为&#x27;OCR.png&#x27;</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;识别中...&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;OCR.png&#x27;</span>, <span class="string">&quot;rb&quot;</span>) <span class="keyword">as</span> fp:</span><br><span class="line">        image = fp.read()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 调用通用文字识别（标准版）</span></span><br><span class="line">        res_image = client.basicGeneral(image)</span><br><span class="line">        <span class="comment"># print(res_image)</span></span><br><span class="line"></span><br><span class="line">        <span class="comment"># 筛选数据</span></span><br><span class="line">        all_text = <span class="string">&#x27;&#x27;</span></span><br><span class="line">        res = res_image[<span class="string">&#x27;words_result&#x27;</span>]</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> res:</span><br><span class="line">            all_text += i[<span class="string">&#x27;words&#x27;</span>] + <span class="string">&#x27;\n&#x27;</span></span><br><span class="line">        a = all_text</span><br><span class="line">        <span class="built_in">print</span>(a + <span class="string">&#x27;-&#x27;</span> * <span class="number">70</span>)</span><br><span class="line"></span><br><span class="line">    <span class="comment">#   --------------- 有道翻译 --------------</span></span><br><span class="line">    <span class="comment"># 网址</span></span><br><span class="line">    url = <span class="string">&#x27;https://fanyi.youdao.com/translate_o?smartresult=dict&amp;smartresult=rule&#x27;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 反爬</span></span><br><span class="line">    header = &#123;</span><br><span class="line">        <span class="string">&#x27;User-Agent&#x27;</span>: conf.get(<span class="string">&#x27;config&#x27;</span>, <span class="string">&#x27;User-Agent&#x27;</span>),</span><br><span class="line">        <span class="string">&#x27;Cookie&#x27;</span>: conf.get(<span class="string">&#x27;config&#x27;</span>, <span class="string">&#x27;Cookie&#x27;</span>),</span><br><span class="line">        <span class="string">&#x27;Referer&#x27;</span>: <span class="string">&#x27;https://fanyi.youdao.com/&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 时间戳</span></span><br><span class="line">    r = <span class="built_in">str</span>(<span class="built_in">int</span>(time.time() * <span class="number">1000</span>))</span><br><span class="line">    <span class="comment"># print(r)</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 随机数</span></span><br><span class="line">    random_num = random.randint(<span class="number">0</span>, <span class="number">9</span>)</span><br><span class="line">    i = r + <span class="built_in">str</span>(random_num)</span><br><span class="line">    <span class="comment"># print(i)</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">data_new</span>(<span class="params">e</span>):</span></span><br><span class="line">        <span class="comment"># md5</span></span><br><span class="line">        str_sign = <span class="string">&quot;fanyideskweb&quot;</span> + e + i + <span class="string">&quot;Ygy_4c=r#e#4EX^NUGUc5&quot;</span></span><br><span class="line">        md5 = hashlib.md5()</span><br><span class="line">        md5.update(str_sign.encode())</span><br><span class="line">        sign = md5.hexdigest()</span><br><span class="line">        <span class="comment"># print(sign)</span></span><br><span class="line"></span><br><span class="line">        data_old = &#123;</span><br><span class="line">            <span class="string">&#x27;i&#x27;</span>: e,</span><br><span class="line">            <span class="string">&#x27;from&#x27;</span>: <span class="string">&#x27;AUTO&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;to&#x27;</span>: <span class="string">&#x27;AUTO&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;smartresult&#x27;</span>: <span class="string">&#x27;dict&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;client&#x27;</span>: <span class="string">&#x27;fanyideskweb&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;salt&#x27;</span>: i,</span><br><span class="line">            <span class="string">&#x27;sign&#x27;</span>: sign,</span><br><span class="line">            <span class="string">&#x27;lts&#x27;</span>: r,</span><br><span class="line">            <span class="string">&#x27;bv&#x27;</span>: conf.get(<span class="string">&#x27;config&#x27;</span>, <span class="string">&#x27;bv&#x27;</span>),</span><br><span class="line">            <span class="string">&#x27;doctype&#x27;</span>: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;version&#x27;</span>: <span class="string">&#x27;2.1&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;keyfrom&#x27;</span>: <span class="string">&#x27;fanyi.web&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;action&#x27;</span>: <span class="string">&#x27;FY_BY_REALTlME&#x27;</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> data_old</span><br><span class="line"></span><br><span class="line">    data = data_new(a)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 请求</span></span><br><span class="line">    result = requests.post(url, headers=header, data=data).text</span><br><span class="line">    <span class="comment"># print(result)</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 数据筛选</span></span><br><span class="line">    dict_res = json.loads(result)</span><br><span class="line">    b = dict_res[<span class="string">&#x27;translateResult&#x27;</span>][<span class="number">0</span>][<span class="number">0</span>][<span class="string">&#x27;tgt&#x27;</span>]</span><br><span class="line">    <span class="built_in">print</span>(b + <span class="string">&#x27;\n&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># copy</span></span><br><span class="line">    pyperclip.copy(a + <span class="string">&#x27;\n&#x27;</span> + b)</span><br><span class="line">    time.sleep(<span class="number">0.02</span>)</span><br><span class="line">    <span class="comment"># 弹窗</span></span><br><span class="line">    root = tk.Tk()</span><br><span class="line">    root.title(<span class="string">&quot;info&quot;</span>)</span><br><span class="line">    tk.Label(root, text=<span class="string">&quot;已复制&quot;</span>, ).pack()       <span class="comment"># 弹窗显示</span></span><br><span class="line">    root.after(<span class="number">1000</span>, <span class="keyword">lambda</span>: root.destroy())    <span class="comment"># 停留1s</span></span><br><span class="line">    root.mainloop()</span><br><span class="line"></span><br></pre></td></tr></table></figure></li><li><p>创建 <code>OCR.ini</code> 文件，<font size="3" color="blue">复制以下内容</font> ， 把在 <strong>准备工作</strong> 获取的 <code>AppID</code> 、 <code>API Key</code> 和 <code>Secret Key</code> <font size="3" color="blue">对应填入</font></p><figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[aip]</span></span><br><span class="line"><span class="attr">APP_ID</span> = 	</span><br><span class="line"><span class="attr">API_KEY</span> = </span><br><span class="line"><span class="attr">SECRET_KEY</span> = </span><br><span class="line"></span><br><span class="line"><span class="section">[config]</span></span><br><span class="line"><span class="attr">User-Agent</span> = Mozilla/<span class="number">5.0</span> (Windows NT <span class="number">6.1</span><span class="comment">; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Cookie</span> = OUTFOX_SEARCH_USER_ID=<span class="number">1870252624</span>@<span class="number">10.110</span>.<span class="number">96.157</span><span class="comment">; OUTFOX_SEARCH_USER_ID_NCOO=1338974472.751384; ___rl__test__cookies=1654489795853</span></span><br><span class="line"></span><br><span class="line"><span class="attr">bv</span> = dbf26599b4389c828cae8b896c9b0708</span><br></pre></td></tr></table></figure></li><li><p>最后自行打包 <strong><font size="3" color="blue">(不打包在pycharm里也能用)</font></strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pyinstaller -F 文件名.py</span><br><span class="line"></span><br><span class="line"><span class="comment"># pyinstaller -F 文件名.pyw</span></span><br></pre></td></tr></table></figure></li></ol><hr><h2 id="打包后-使用教程"><a href="#打包后-使用教程" class="headerlink" title="打包后 使用教程"></a>打包后 使用教程</h2><font size="3"><div class="note warning flat"><p><strong>代码已打包上传到 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/12thstan/baidu-OCR-fanyi">github</a> 和 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://gitee.com/c12th/baidu-OCR-fanyi">gitee</a> 上</strong></p></div></font><ul><li>打开 <code>new_OCR\dist\OCR.ini</code> 文件，把在 <strong>准备工作</strong> 获取的 <code>AppID</code> 、 <code>API Key</code> 和 <code>Secret Key</code> <font size="3" color="blue">对应填入</font> ， <strong>运行exe文件</strong> 即可<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[aip]</span></span><br><span class="line"><span class="attr">APP_ID</span> = </span><br><span class="line"><span class="attr">API_KEY</span> = </span><br><span class="line">SECRET_KEY = </span><br></pre></td></tr></table></figure></li></ul><hr><ul><li><p><font size="3" color="red">如出现闪退</font> / <font size="3" color="blue">想换成自己的</font> , <font size="3" color="red">请</font> / <font size="3" color="blue">可</font> 更换以下内容</p><figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">[config]</span></span><br><span class="line"><span class="attr">User-Agent</span> = </span><br><span class="line"></span><br><span class="line"><span class="attr">Cookie</span> = </span><br><span class="line"></span><br><span class="line">bv = </span><br></pre></td></tr></table></figure></li><li><p>方法如下</p></li></ul><ol><li><p><kbd>F12</kbd> 打开 <strong>开发者工具</strong> ，选择 <font size="3" color="blue">Network</font> ， 然后选择 <font size="3" color="red">XHR</font></p></li><li><p>在 <strong>翻译框</strong> 输入任意 <strong>文字</strong> ，<strong>页面</strong> 会出现 <font size="3" color="blue">translate_</font> <font size="3" color="red">(如有多个选最新)</font></p></li><li><p>点击 <font size="3" color="blue">translate_</font> ，在 <font size="3" color="blue">Headers</font> 页面可以找到 <code>User-Agent</code> 和 <code>Cookie</code> ,在 <font size="3" color="blue">Payload</font> 页面可以找到<code>bv</code> <strong><font size="3" color="red">(火狐浏览器的 <code>bv</code> 在请求页面)</font></strong></p></li><li><p>把找到的内容 <font size="3" color="blue">替换 ini 文件内容</font> ，<font size="3" color="red">重新运行</font> 即可</p></li><li><p>如 <strong>不清楚文字描述</strong> 可按 <font size="3" color="red">如图 1 所示</font> 步骤 即可</p></li></ol><p><img src="/img/loading.gif" data-lazy-src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.15/img/2022.6.2-2.gif" width="700"></p><p align="center">图 1</p><hr><h1 id="最后"><a href="#最后" class="headerlink" title="最后"></a>最后</h1><div class="tip warning faa-horizontal"><p>代码已在 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/12thstan/baidu-OCR-fanyi">github</a> 和 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://gitee.com/c12th/baidu-OCR-fanyi">gitee</a> 上开源</p></div><div class="tip info faa-horizontal animated-hover"><p><strong><font size="3" color="cyan">这个百度 OCR 只能翻译第一行的内容，多行无法翻译</font></strong></p></div><div class="tip cogs faa-parent animated-hover"><p class="faa-horizontal">个人版的调用次数已经够用了，不建议多对一，建议一对一</p></div><hr></article><div class="business-center"><div class="business-card"><div class="business-flip"><div class="business-front"><div class="business-strip-bottom"></div><div class="business-strip-top"></div><img class="business-logo" width="80" height="80" src="https://pic.imgdb.cn/item/624aa2d5239250f7c5147559.png" alt="cardcode"><div class="business-Invitation">Invitation</div><div class="business-chip"><div class="business-chip-line"></div><div class="business-chip-line"></div><div class="business-chip-line"></div><div class="business-chip-line"></div><div class="business-chip-main"></div></div><svg class="business-wave" viewBox="0 3.71 26.959 38.787" width="26.959" height="38.787" fill="white"><path d="M19.709 3.719c.266.043.5.187.656.406 4.125 5.207 6.594 11.781 6.594 18.938 0 7.156-2.469 13.73-6.594 18.937-.195.336-.57.531-.957.492a.9946.9946 0 0 1-.851-.66c-.129-.367-.035-.777.246-1.051 3.855-4.867 6.156-11.023 6.156-17.718 0-6.696-2.301-12.852-6.156-17.719-.262-.317-.301-.762-.102-1.121.204-.36.602-.559 1.008-.504z"></path><path d="M13.74 7.563c.231.039.442.164.594.343 3.508 4.059 5.625 9.371 5.625 15.157 0 5.785-2.113 11.097-5.625 15.156-.363.422-1 .472-1.422.109-.422-.363-.472-1-.109-1.422 3.211-3.711 5.156-8.551 5.156-13.843 0-5.293-1.949-10.133-5.156-13.844-.27-.309-.324-.75-.141-1.114.188-.367.578-.582.985-.542h.093z"></path><path d="M7.584 11.438c.227.031.438.144.594.312 2.953 2.863 4.781 6.875 4.781 11.313 0 4.433-1.828 8.449-4.781 11.312-.398.387-1.035.383-1.422-.016-.387-.398-.383-1.035.016-1.421 2.582-2.504 4.187-5.993 4.187-9.875 0-3.883-1.605-7.372-4.187-9.875-.321-.282-.426-.739-.266-1.133.164-.395.559-.641.984-.617h.094zM1.178 15.531c.121.02.238.063.344.125 2.633 1.414 4.437 4.215 4.437 7.407 0 3.195-1.797 5.996-4.437 7.406-.492.258-1.102.07-1.36-.422-.257-.492-.07-1.102.422-1.359 2.012-1.075 3.375-3.176 3.375-5.625 0-2.446-1.371-4.551-3.375-5.625-.441-.204-.676-.692-.551-1.165.122-.468.567-.785 1.051-.742h.094z"></path></svg><div class="business-card-number"><div class="business-section">Reverse</div><div class="business-section">835786725</div></div><div class="business-end"><span class="business-end-text">created:</span><span class="business-end-date">06/08/2022</span></div><div class="business-card-holder">HY Group</div><div class="business-master"><div class="business-circle business-master-red"></div><div class="business-circle business-master-yellow"></div></div></div><div class="business-back"><div class="business-strip-black"></div><div class="business-ccv"><label>sitelink</label><div><a href="https://blog.c12th.cn">https://blog.c12th.cn</a></div></div><div class="business-terms"><p>HY Group , Entertainment first , Just be happy . SuiXing Originality Parking Iot . Ruan Fan Ying Chi Herbal Tea Shop .</p><p>Internet Of Things .</p></div></div></div></div></div><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者:</span> <span class="post-copyright-info"><a href="mailto:undefined" rel="external nofollow noreferrer">Reverse</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接:</span> <span class="post-copyright-info"><a href="https://blog.c12th.cn/archives/7.html">https://blog.c12th.cn/archives/7.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://blog.c12th.cn" target="_blank">Reverse</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%88%86%E4%BA%AB/">分享</a><a class="post-meta__tags" href="/tags/python/">python</a></div><div class="post_share"><div class="addtoany"><div class="a2a_kit a2a_kit_size_32 a2a_default_style"><a class="a2a_button_wechat"></a><a class="a2a_button_sina_weibo"></a><a class="a2a_button_email"></a><a class="a2a_button_copy_link"></a><a class="a2a_dd" target="_blank" rel="noopener external nofollow noreferrer" href="https://www.addtoany.com/share"></a></div></div><script async src="https://static.addtoany.com/menu/page.js"></script></div></div><link rel="stylesheet" href="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/diy/coin.css" media="defer" onload='this.media="all"'><div class="post-reward"><button class="tip-button reward-button"><span class="tip-button__text">打赏</span><div class="coin-wrapper"><div class="coin"><div class="coin__middle"></div><div class="coin__back"></div><div class="coin__front"></div></div></div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://pic.imgdb.cn/item/624aa2db239250f7c51480f0.jpg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" data-lazy-src="https://pic.imgdb.cn/item/624aa2db239250f7c51480f0.jpg" alt="微信"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://pic.imgdb.cn/item/624aa2db239250f7c51480ed.jpg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" data-lazy-src="https://pic.imgdb.cn/item/624aa2db239250f7c51480ed.jpg" alt="支付宝"></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></button></div><audio id="coinAudio" src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/diy/coin.mp3"></audio><script defer src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/diy/coin.js"></script><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/archives/6.html"><img class="next-cover" data-lazy-src="https://pic.imgdb.cn/item/629321e10947543129228d44.png" onerror='onerror=null,src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/img/505.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">把github贡献日历部署到博客上(二)</div></div></a></div></nav><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="waline-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas iconfont icon-zhankaimulu"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%99%BE%E5%BA%A6OCR"><span class="toc-number">2.</span> <span class="toc-text">百度OCR</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C"><span class="toc-number">2.1.</span> <span class="toc-text">准备工作</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%B8%E5%BF%83%E4%BB%A3%E7%A0%81"><span class="toc-number">2.2.</span> <span class="toc-text">核心代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%9C%89%E9%81%93%E7%BF%BB%E8%AF%91"><span class="toc-number">3.</span> <span class="toc-text">有道翻译</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%A1%A5%E5%85%85"><span class="toc-number">4.</span> <span class="toc-text">补充</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95"><span class="toc-number">4.1.</span> <span class="toc-text">拓展</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%93%E5%8C%85%E5%89%8D-%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81"><span class="toc-number">4.2.</span> <span class="toc-text">打包前 完整代码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%93%E5%8C%85%E5%90%8E-%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B"><span class="toc-number">4.3.</span> <span class="toc-text">打包后 使用教程</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%9C%80%E5%90%8E"><span class="toc-number">5.</span> <span class="toc-text">最后</span></a></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright"><span>&copy;2021 - 2022</span><svg style="width:1.8em;height:1.8em" aria-hidden="true"><use xlink:href="#icon-Butterfly"></use></svg><span>Reverse</span></div><div class="footer_custom_text"><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral"><img src="\img\logo5.png" height="50" width="80" title="本网站由 又拍云 提供CDN加速/云存储服务"></a><br><a><a style="margin-inline:5px" target="_blank" href="https://hexo.io/" rel="external nofollow noreferrer"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为Hexo_v5.4.0"></a><a style="margin-inline:5px" target="_blank" href="https://butterfly.js.org/" rel="external nofollow noreferrer"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题版本为Butterfly_v3.7.0"></a><a style="margin-inline:5px" target="_blank" href="https://www.jsdelivr.com/" rel="external nofollow noreferrer"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用JsDelivr为静态资源提供CDN加速"></a><a style="margin-inline:5px" target="_blank" href="https://vercel.com/" rel="external nofollow noreferrer"><img src="https://img.shields.io/badge/Hosted-Vercel-brightgreen?style=flat&logo=Vercel" title="本站托管于Vercel"></a></a><a style="margin-inline:5px" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer"><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Claris" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a><a style="margin-inline:5px" target="_blank" href="https://icp.gov.moe/?keyword=20220224" rel="external nofollow noreferrer"><img src="https://img.shields.io/badge/%E8%90%8CICP%E5%A4%87-20220224-fe1384?style-flat&logo=" title="萌ICP备20220224号"></a></div></div></footer></div><a href="#" class="cd-top faa-float animated"></a><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换">繁</button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas iconfont icon-24gl-swapHorizontal"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas iconfont icon-weibiaoti- fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas iconfont icon-zhankaimulu"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas iconfont icon-liaotian"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas iconfont icon-huidingbu"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div></div><hr><div id="local-search-results"></div><span class="search-close-button"><i class="fas iconfont icon-guanbi2"></i></span></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line"><a class="rightMenu-item" id="menu-link" href="/random.html"><i class="fa-solid fa-shoe-prints"></i><span>随便逛逛</span></a><a class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简切换</span></a><a class="rightMenu-item" id="menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>标签</span></a><a class="rightMenu-item" id="menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>分类</span></a></div></div><div id="rightmenu-mask" onclick="RemoveRightMenu()"></div><div><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/utils.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/main.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.4/butterfly/js/tw_cn.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/instantpage.min.js" type="module"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/snackbar.min.js"></script><script>function panguFn(){"object"==typeof pangu?pangu.autoSpacingPage():getScript("https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/pangu.min.js").then(()=>{pangu.autoSpacingPage()})}function panguInit(){panguFn()}document.addEventListener("DOMContentLoaded",panguInit)</script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/local-search.js"></script><script>var preloader={endLoading:()=>{document.body.style.overflow="auto",document.getElementById("loading-box").classList.add("loaded")},initLoading:()=>{document.body.style.overflow="",document.getElementById("loading-box").classList.remove("loaded")}};window.addEventListener("load",preloader.endLoading())</script><div class="js-pjax"><script>function loadWaline(){function e(){new Waline(Object.assign({el:"#waline-wrap",serverURL:"https://waline.c12th.cn",avatar:"",path:location.pathname,emojiCDN:"",emojiMaps:"",visitor:!0},null))}"function"==typeof Waline?e():getScript("https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/Waline.min.js").then(e)}{function loadOtherComment(){loadWaline()}btf.loadComment(document.getElementById("waline-wrap"),loadWaline)}</script></div><script src="//geoip-js.com/js/apis/geoip2/v2.1/geoip2.js"></script><script src="/js/ip.js"></script><video muted loop id="bgvid"><source src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/img/01.mp4" type="video/mp4"><source src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/img/01.ogg" type="video/ogg"><source src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/img/01.webm" type="video/webm"></video><script>document.addEventListener("click",(function(){document.getElementById("bgvid").play()}))</script><div class="aplayer no-destroy" data-id="4989347813" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listfolded="true" data-order="random" data-preload="auto" data-autoplay="false" muted></div><script async src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.3/butterfly/diy/grayscale.js"></script><script async src="//at.alicdn.com/t/font_2264842_3izu8i5eoc2.js"></script><script async src="//at.alicdn.com/t/font_2032782_ev6ytrh30f.js"></script><script async src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.3/butterfly/diy/diytitle.js"></script><script src="/js/daovoice.js"></script><script src="https://myhkw.cn/player/js/player.js" id="myhk" key="159611061656" m="1"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.12/butterfly/diy/timing.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script async data-pjax src="https://gcore.jsdelivr.net/gh/zhheo/JS-Heo@main/rightmenu/rightmenu.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.17/butterfly/swiper/swiper.min.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.17/butterfly/swiper/swiperindex.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,POWERMODE.mobile=!1,document.body.addEventListener("input",POWERMODE)</script><script id="click-heart" src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/click-heart.min.js" async mobile="false"></script><link rel="stylesheet" href="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/css/APlayer.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/APlayer.min.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/Meting.min.js"></script><script src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/js/pjax.min.js"></script><script>let pjaxSelectors=["title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach(e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach(e=>t.setAttribute(e.name,e.value)),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)}),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:send",(function(){if("object"==typeof preloader&&preloader.initLoading(),window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode")})),document.addEventListener("pjax:error",e=>{404===e.request.status&&pjax.loadUrl("/404.html")})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script data-pjax src="https://npm.elemecdn.com/reverse-stu-allversions@1.0.1/butterfly/diy/hexo_githubcalendar.js"></script><script data-pjax>function GithubCalendarConfig(){var t=document.getElementById("recent-posts");t&&"/"==location.pathname&&(console.log("已挂载github calendar"),t.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="width:100%;height:auto;padding:10px;"><div id="github_loading" style="width:10%;height:100%;margin:0 auto;display: block"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve"><path fill="#d0d0d0" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform></path></svg></div><div id="github_container"></div></div>')),GithubCalendar("https://python-github-calendar-api-six.vercel.app/api?12thstan",["#ebedf0","#f1f8ff","#dbedff","#c8e1ff","#79b8ff","#2188ff","#0366d6","#005cc5","#044289","#032f62","#05264c"],"12thstan")}document.getElementById("recent-posts")&&GithubCalendarConfig()</script><style>#github_container{min-height:280px}@media screen and (max-width:650px){#github_container{min-height:0}}</style><style></style><script data-pjax>function butterfly_clock_injector_config(){var c=document.getElementsByClassName("sticky_layout")[0];console.log("已挂载butterfly_clock"),c.insertAdjacentHTML("afterbegin",'<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://npm.elemecdn.com/hexo-butterfly-clock@1.0.7/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>')}for(var elist="/archives/".split(","),cpage=location.pathname,epage="all",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_clock_injector_config()</script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.js"></script><div class="js-pjax"><script async>for(var arr=document.getElementsByClassName("recent-post-item"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration","500ms"),arr[i].setAttribute("data-wow-delay","500ms"),arr[i].setAttribute("data-wow-offset","1"),arr[i].setAttribute("data-wow-iteration","1")</script><script async>for(var arr=document.getElementsByClassName("card-widget"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset",""),arr[i].setAttribute("data-wow-iteration","")</script></div><script defer src="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/wow_init.js"></script><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script></body></html>